//
//  NSTimer+Extension.m
//  AccountEasy
//
//  Created by 黄志刚 on 2020/8/19.
//  Copyright © 2020 AccountEasy. All rights reserved.
//

#import "NSTimer+Extension.h"

@implementation NSTimer (Extension)

- (void)pause {

    if ([self isValid]) { [self setFireDate:[NSDate distantFuture]]; }
}

- (void)restart {

    if ([self isValid]) { [self setFireDate:[NSDate date]]; }
}

- (void)restartAfterTimeInterval:(NSTimeInterval)interval {

    if ([self isValid]) { [self setFireDate:[NSDate dateWithTimeIntervalSinceNow:interval]]; }
}

#pragma mark - ------------- block时间回调 -------------
+ (void)_zz_ExecBlock:(NSTimer *)timer {
    if ([timer userInfo]) {
        void (^block)(NSTimer *timer) = (void (^)(NSTimer *timer))[timer userInfo];
        block(timer);
    }
}

+ (NSTimer *)zz_scheduledTimerWithTimeInterval:(NSTimeInterval)seconds
                                       repeats:(BOOL)repeats
                                         block:(void (^)(NSTimer *timer))block {
    return [NSTimer scheduledTimerWithTimeInterval:seconds
                                            target:self
                                          selector:@selector(_zz_ExecBlock:)
                                          userInfo:[block copy]
                                           repeats:repeats];
}

@end
